package qf.sail.dao.impl;

import org.apache.commons.dbutils.QueryRunner;
import qf.sail.dao.AddressDao;
import qf.sail.entity.Address;
import qf.sail.entity.Good;
import qf.sail.util.DBUtil;

import java.sql.SQLException;
import java.util.List;

public class AddressDaoImpl implements AddressDao {

    private QueryRunner queryRunner = new QueryRunner(DBUtil.getDataSource());

    /**
     * 获取某个用户的地址列表
     * @param accountId
     * @return
     */
    @Override
    public List<Address> getAddressListByAccountId(long accountId) {
        String sql = "select * from address where account_id = ?";
        Object[] params = {accountId};
        List<Address> addressList = null;
        try {
            addressList = queryRunner.query(sql, DBUtil.getBeanListHandler(Address.class),params);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return addressList;
    }
}
